function newDic(dicurl) {
	var table = $('#update_table');
	var search_table = $('#search_table');
	var pCode = $('#p_code').val();
	table.show();
	search_table.hide();
	greyLayer.open();
	win.window('open');
	// 动态生成表格	
	form.form('clear');
	$('#p_code').val(pCode);
	$('#ido').val("add");
	form.url = dicurl+"saveDic/";
}
function searchFormOpen(dicurl) {
//	debugger;
	var table = $('#update_table');
	var search_table = $('#search_table');
	var pCode = $('#p_code').val();
	table.hide();
	search_table.show();
	greyLayer.open();
	searchWin.window('open');
	// 动态生成表格	
	searchForm.form('clear');
	$('#p_code').val(pCode);
	$('#ido').val("search");
	searchForm.url = dicurl+"searchDic/";
}
function editDic(dicurl) {
	//debugger;
	var table = $('#update_table');
	var search_table = $('#search_table');
	table.show();
	search_table.hide();
	$('#ido').val("add");
	var row = grid.datagrid('getSelected');
	if (row) {
		greyLayer.open();
		win.window('open');
		$('#c_seq').val(row.c_seq);
		$('#c_code').val(row.c_code);
		$('#c_name').val(row.c_name);
		$('#attr').val(row.attr);
		$('#is_active').val(row.is_active);
		form.url =  dicurl+'updateDic?c_seq=' + row.c_seq;

	} else {
		sys_alert('错误提示', '选择一个要操作的功能', 'error');
	}
}
function saveDic() {
	var whatdo = $('#ido').val();
	if(whatdo == 'add'){
		if (form.form('validate')) {
			form.form('submit', {
						url : form.url,//dicurl+'saveDic?c_seq=' + row.c_seq,
						success : function(data) {
							eval('data=' + data);
							if (data.success) {
								grid.datagrid('reload');
								win.window('close');
								greyLayer.close();
							} else {
								sys_alert('错误提示', data.msg, 'error');
							}
						}
					});
		}
	}else{
		var pageNum = $('#tt1').datagrid('options').pageNumber;
		var pageSize = $('#tt1').datagrid('options').pageSize;
		//alert(pageNum + "-" + pageSize);
		searchForm.form('submit', {
			url : searchForm.url+'?c_name='+$('#s_c_name').val()+'&c_code='+$('#s_c_code').val()+'&rows='+pageSize+'&page='+pageNum,//dicurl+'saveDic?c_seq=' + row.c_seq,
			success : function(data) {
					eval('data=' + data);
					if (data.success) {
					searchWin.window('close');
					greyLayer.close();
					grid.datagrid('loadData',data);
				} else {
					sys_alert('错误提示', data.msg, 'error');
				}
			}
		});
	}
}
function delDic(dicurl) {
	//debugger;
	var ids = [];
	var rows = $('#tt1').datagrid('getSelections');
	for(var i=0; i<rows.length; i++){
		ids.push(rows[i].c_seq);
	}
	
	if (ids.length != 1){
		top.$.messager.alert('提示信息','请选择一条记录进行操作!','info');
		return;
	}
	//更改前询问
	$.messager.confirm("用户确认", "确定要切换字典状态？", function(r) {
				if (r) {
					var row = grid.datagrid('getSelected');
					if (row) {
						form.url =  dicurl+'changeActive?c_seq=' + row.c_seq;
						form.form('submit', {
									url : form.url,
									success : function(data) {
										eval('data=' + data);
										if (data.success) {
											grid.datagrid('reload');
										} else {
											sys_alert('错误提示', data.msg, 'error');
										}
									}
								});
					} else {
						sys_alert('错误提示', '选择一个要操作的功能', 'error');
					}

				}
			});
}
function cancelDic(dicurl) {
	
	var ids = [];
	var rows = $('#tt1').datagrid('getSelections');
	for(var i=0; i<rows.length; i++){
		ids.push(rows[i].c_seq);
	}
	
	if (ids.length ==0){
		top.$.messager.alert('提示信息','请选择一条记录进行操作!','info');
		return;
	}
	
	// 删除前询问
	$.messager.confirm("用户确认", "确定要删除字典？", function(r) {
				if (r) {
					var row = grid.datagrid('getSelected');
					
					if (row) {
						form.url =  dicurl+'cancelDic?c_seq=' + ids ;
						form.form('submit', {
									url : form.url,
									success : function(data) {
										eval('data=' + data);
										if (data.success) {
											grid.datagrid('reload');
										} else {
											sys_alert('错误提示', data.msg, 'error');
										}
									}
								});
					} else {
						sys_alert('错误提示', '选择一个要操作的功能', 'error');
					}

				}
			});

}



function closeWindow() {
	win.window('close');
	searchWin.window('close');
	greyLayer.close();
}
